const express = require('express');
const asyncHandler = require('express-async-handler');
const authControl = require('../controllers/auth.controller')
const basicControl = require('../controllers/basic.controller');
const reportControl = require('../controllers/report.controller')
const router = express.Router();
module.exports = router;


//登陆
router.post('/login', asyncHandler(login));
router.get('/logout', asyncHandler(logout));

// router.post('/resetPassword',asyncHandler(resetPassword));

//获取摄像头列表及摄像头直播信息 done
router.post('/getHomePageDevices', asyncHandler(getHomePageDevices));


//根据类型获取展示表信息
router.post('/getProjectManagementInfos', asyncHandler(getProjectManagementInfosPost));
router.post('/getHomePageDevicesImpl', asyncHandler(getHomePageDevicesImpl));

//获取所有展示表信息
router.get('/getProjectManagementInfos', asyncHandler(getProjectManagementInfosGet))

//获取当前工地铭牌，提供项目铭牌
router.post('/getSiteNamePlate', asyncHandler(getSiteNamePlate))

router.post('/getReportsWithTypeByDuration', asyncHandler(getReportsWithTypeByDuration));


router.post('/getChartsInfoByDuration', asyncHandler(getChartsInfoByDuration))

router.post('/getRobotInfos', asyncHandler(getRobotInfos));

async function login(req, res) {
    let user = await authControl.verifyUser(req.body);
    res.json(user)
}

async function logout(req, res) {
    let user = await authControl.logout(req.query.userName);
    res.json(user)
}


async function getHomePageDevices(req, res) {
    let result = await basicControl.getHomePageDevices(req.body);
    res.json(result)
}

async function getHomePageDevicesImpl(req, res) {
    let result = await basicControl.getHomePageDevicesImpl(req.body.unionId);
    res.json(result)
}

async function getProjectManagementInfosPost(req, res) {
    let result = await basicControl.getProjectManagementInfos(req.body)
    res.json(result)

}

async function getProjectManagementInfosGet(req, res) {
    let result = await basicControl.getProjectManagementInfos(req.query)
    res.json(result)
}

async function getSiteNamePlate(req, res) {
    let result = await basicControl.getSiteNamePlate(req.body)
    res.json(result)
}

async function getReportsWithTypeByDuration(req, res) {
    let result = await reportControl.getReportByTypeWithDuration(req.body)
    res.json(result)
}


async function getChartsInfoByDuration(req, res) {
    let result = await basicControl.getChartsInfoByDuration(req.body)
    res.json(result)
}

async function getRobotInfos(req, res) {
    let result = await basicControl.getRobotInfos(req.body)
    res.json(result)
}